package com.gadgets.test.suite;

import com.alibaba.druid.pool.DruidDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;

import javax.sql.DataSource;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2022-01-20
 */
@ContextConfiguration
@ConditionalOnClass(name="GadgetsBm04Start")
@Configuration
public class IrmTestDbConf {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Value("${irm.datasource.url}")
    private String irmDbUrl;
    @Value("${irm.datasource.username}")
    private String irmDbUserName;
    @Value("${irm.datasource.password}")
    private String irmDbPassword;
    @Value("${irm.datasource.driverClassName}")
    private String irmDbDriverClass;

    @Bean(name = "irmDbTestSource")
    public DataSource irmDataSource() {
        logger.info("注册irm数据源");
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setDriverClassName(irmDbDriverClass);
        druidDataSource.setUrl(irmDbUrl);
        druidDataSource.setUsername(irmDbUserName);
        druidDataSource.setPassword(irmDbPassword);
        return druidDataSource;
    }

}
